package com.example.mybiadushoujiweishi.activity.acivitys;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.mybiadushoujiweishi.R;
import com.example.mybiadushoujiweishi.activity.acivitys.base.BaseActivity;
import com.example.mybiadushoujiweishi.activity.acivitys.utils.DanceWageTimer;
import com.example.mybiadushoujiweishi.activity.acivitys.views.RatingBar;
import com.example.mybiadushoujiweishi.activity.acivitys.views.RatingView;

import java.util.Random;

import butterknife.BindView;
import butterknife.OnClick;

public class MainActivity extends BaseActivity {

    int one; //或者：(int) (Math.random() * 10)
    int two;
    int three;
    int num;
    @BindView(R.id.imguser)
    ImageView imguser;
    @BindView(R.id.btn_center)
    TextView btnCenter;
    @BindView(R.id.btn_centertwo)
    TextView btnCentertwo;
    @BindView(R.id.rating_view)
    RatingView view;
    @BindView(R.id.bbx)
    TextView bbx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        one = new Random().nextInt(10) + 1; //或者：(int) (Math.random() * 10)
        two = new Random().nextInt(10) + 1;
        three = new Random().nextInt(10) + 1;
        view = (RatingView) this.findViewById(R.id.rating_view);

        final RatingBar bar1 = new RatingBar(one, (one >= 8) ? "清晰度高" : (one <= 5 ? "清晰度底" : "清晰度中"));
        final RatingBar bar2 = new RatingBar(two, "清洁度");
        final RatingBar bar3 = new RatingBar(three, "流畅度");

        view.addRatingBar(bar1);
        view.addRatingBar(bar2);
        view.addRatingBar(bar3);

        view.show();

        xuanzhuan();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            view.setDefaultColor(getColor(R.color.colorWhite));
        }
        view.show();

        RatingBar hard = new RatingBar(10, "HARD");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            hard.setRatingBarColor(getColor(R.color.colorWhite));
        }

        btnCenter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                one = new Random().nextInt(10) + 1; //或者：(int) (Math.random() * 10)
                two = new Random().nextInt(10) + 1;
                three = new Random().nextInt(10) + 1;
                view.clear();
                bar1.setRate(one);
                bar2.setRate(two);
                bar3.setRate(three);
                xuanzhuan();
                view.show();


            }
        });
    }


    @Override
    public int getContentView() {
        return R.layout.activity_main;
    }

    @Override
    public void initData() {

    }

    public void xuanzhuan() {
        view.setAnimatorListener(new RatingView.AnimatorListener() {
            @Override
            public void onRotateStart() {

            }

            @Override
            public void onRotateEnd() {
                btnCenter.setVisibility(View.VISIBLE);
                btnCentertwo.setVisibility(View.VISIBLE);
                num = (int) ((one * 0.5 + two * 0.3 + three * 0.2) * 10);
                long totaExecuta = DanceWageTimer.getTotalExecuteTime(num, 20);
                DanceWageTimer danceWageTimer = new DanceWageTimer(totaExecuta, 20, btnCenter, num);
                danceWageTimer.start();

            }

            @Override
            public void onRatingStart() {

            }

            @Override
            public void onRatingEnd() {

            }
        });

    }

    public void imgoncilick(View view) {

        Intent intent = new Intent(MainActivity.this, LogiuserActivity.class);

        startActivity(intent);

    }

    @OnClick(R.id.bbx)
    public void onViewClicked() {

        startActivity(new Intent(this,BBXActivity.class));


    }
}
